﻿using System;
using System.Collections.Generic;
using System.Linq;
using battlenet.wow.rt.domain.objects;
using battlenet.wow.rt.sdk.data.dto;
using battlenet.wow.rt.sdk.objects.Mapper;
using battlenet.wow.rt.sdk.utility;

namespace battlenet.wow.rt.sdk.objects.mapper
{
    internal class ItemDetailMapper : Remapper<ItemDetail>
    {
        public override void RegisterMappers()
        {
            Register(typeof(ItemDetailInfo), input => Map(input as ItemDetailInfo));
        }

        internal ItemDetail Map(ItemDetailInfo info)
        {
            var detail = new ItemDetail();
            detail.AllowableClasses = info.AllowableClasses == null ? new List<CharacterClass>() : info.AllowableClasses.Select(classId => Classes.Class[classId]).ToList();
            detail.Armor = info.Armor;
            detail.SellPrice = new Price(info.SellPrice);
            detail.AvailableContexts = info.AvailableContexts == null ? new List<string>() : info.AvailableContexts.ToList();
            detail.BaseArmor = info.BaseArmor;
            detail.BonusLists = info.BonusLists == null ? new List<int>() : info.BonusLists.ToList();
            detail.BonusStats = info.BonusStats == null ? new List<Statistic>() : info.BonusStats.Select(s => new Statistic(s.Stat, s.Amount)).ToList();
            detail.BuyPrice = new Price(info.BuyPrice);
            detail.ContainerSlots = info.ContainerSlots;
            detail.Context = info.Context;
            detail.Description = info.Description;
            detail.DisplayInfoId = info.DisplayInfoId;
            detail.Equippable = info.Equippable;
            detail.HasSockets = info.HasSockets;
            detail.HeroicTooltip = info.HeroicTooltip;
            detail.Icon = info.Icon;
            detail.Id = info.Id;
            detail.InventoryTypeId = info.InventoryType;
            detail.IsAuctionable = info.IsAuctionable;
            detail.ItemBindId = info.ItemBind;
            detail.ItemClassId = info.ItemClass;
            detail.ItemLevel = info.ItemLevel;
            detail.ItemSource = info.ItemSource == null ? new ItemSource() : new ItemSource {SourceId = info.ItemSource.SourceId, SourceType = info.ItemSource.SourceType};
            detail.ItemSpells = info.ItemSpells == null ? new List<ItemSpell>() : info.ItemSpells.Select(spell => spell.Remap(new ItemSpellMapper())).ToList();
            detail.Name = info.Name;
            detail.ItemSubClassId = info.ItemSubclass;
            detail.MaxCount = info.MaxCount;
            detail.MaxDurability = info.MaxDurability;
            detail.MinFactionId = info.MinFactionId;
            detail.MinReputation = info.MinReputation;
            detail.NameDescription = info.NameDescription;
            detail.NameDescriptionColor = info.NameDescriptionColor;
            detail.QualityId = info.Quality;
            detail.RequiredLevel = info.RequiredLevel;
            detail.RequiredSkill = info.RequiredSkill;
            detail.RequiredSkillRank = info.RequiredSkillRank;
            detail.Stackable = info.Stackable;
            detail.Upgradable = info.Upgradable;
            detail.WeaponInfo = info.WeaponInfo == null ? new WeaponItem() : info.WeaponInfo.Remap(new WeaponItemMapper(SlotType.MainHand));
            detail.SocketInfo = info.SocketInfo == null ? new ItemSockets() : info.SocketInfo.Remap(new ItemSocketsMapper());
            detail.DisenchantingSkillRank = info.DisenchantingSkillRank;

            return detail;
        }
    }
}
